package com.sunny.l26;

public class Solution {

    public static void main(String[] args) {

        new Solution().isPalindrome("8V8K;G;K;V;");

    }

    public boolean isPalindrome(String s) {
        if(null == s || "".equals(s))
            return true;
        int i = 0;
        int j = s.length()-1;
        s = s.toLowerCase();
        boolean flag = true;
        while (i<j){
            while (i<s.length() && (( s.charAt(i)<'a' || s.charAt(i)>'z')  && (s.charAt(i)<'0' || s.charAt(i)>'9'))){
//                System.out.println(i + " " + s.charAt(i));
                i++;
            }
            while (j>=0 && ((s.charAt(j)<'a' || s.charAt(j)>'z') && (s.charAt(j)<'0' || s.charAt(j)>'9'))){
                j--;
            }
            if(i>=j){
                break;
            }
//            System.out.println(s.charAt(i) + " " + s.charAt(j));
            if(s.charAt(i) != s.charAt(j)){
                flag = false;
                break;
            }
            i++;
            j--;
        }
        return flag;
    }
}